Generating and using checkpoints in a virtual computer system

ABSTRACT

To generate a checkpoint for a virtual machine (VM), first, while the VM is still running, a copy-on-write (COW) disk file is created pointing to a parent disk file that the VM is using. Next, the VM is stopped, the VM&#39;s memory is marked COW, the device state of the VM is saved to memory, the VM is switched to use the COW disk file, and the VM begins running again for substantially the remainder of the checkpoint generation. Next, the device state that was stored in memory and the unmodified VM memory pages are saved to a checkpoint file. Also, a copy may be made of the parent disk file for retention as part of the checkpoint, or the original parent disk file may be retained as part of the checkpoint. If a copy of the parent disk file was made, then the COW disk file may be committed to the original parent disk file.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application is a Continuation of U.S. patent application Ser. No.12/435,235, filed May 4, 2009, now issued as U.S. Pat. No. 7,971,015,which is a Continuation of U.S. patent application Ser. No. 10/705,919,filed Dec. 31, 2003, now issued as U.S. Pat. No. 7,529,897.

BACKGROUND OF THE INVENTION

Field of the Invention

This invention relates to virtual computer systems, and, in particular,to a system and method for generating a checkpoint for an active virtualmachine and for executing a virtual machine from a previously generatedcheckpoint.

Description of the Related Art

The advantages of virtual machine technology have become widelyrecognized. Among these advantages is the ability to run multiplevirtual machines on a single host platform. This makes better use of thecapacity of the hardware, while still ensuring that each user enjoys thefeatures of a “complete,” isolated computer.

The advantages of various types of checkpointing are also widelyrecognized, such as providing a backup of some aspect of a computersystem and providing the ability to revert back to a previouslygenerated checkpoint to undo changes to some aspect of a computer systemor to recover from a failure affecting the computer system. Oneparticular use of checkpointing that is advantageous is to capture thestate of a long-running computation, so that, if the computation failsat some point, it can be resumed from the checkpointed state, instead ofhaving to restart the computation from the beginning.

This invention relates to the generation and use of checkpoints for avirtual machine within a virtual computer system. Accordingly, virtualmachine technology and checkpointing technology are both discussedbelow.

General Virtualized Computer System

As is well known in the field of computer science, a virtual machine(VM) is a software abstraction—a “virtualization”—of an actual physicalcomputer system. FIG. 1 illustrates, in part, the general configurationof a virtual computer system 700, including a virtual machine 200, whichis installed as a “guest” on a “host” hardware platform 100.

As FIG. 1 shows, the hardware platform 100 includes one or moreprocessors (CPUs) 110, system memory 130, and one or more local storagedevices, which typically includes a local disk 140. The system memory istypically some form of high-speed RAM (random access memory), whereasthe disk (one or more) is typically a non-volatile, mass storage device.The hardware 100 also typically includes other conventional mechanismssuch as a memory management unit (MMU) 150 and various registers 160.The hardware 100 may also include one or more interface cards forinterfacing with external devices, computers, systems and/or networks.For example, the hardware 100 may include a data interface 170 forconnecting to an external data storage device, system or network. As amore specific example, the data interface 170 may be one or moreconventional host bus adapters (HBAs) for connecting to a conventionalstorage area network (SAN). Also, the hardware 100 may include a networkinterface 180 for connecting to a computer network. More specifically,the network interface 180 may be, for example, one or more conventionalEthernet controllers or network interface cards (NICs) for connecting toa conventional Ethernet network, which may further be connected to oneor more additional networks of varying types.

Each VM 200 typically includes at least one virtual CPU 210, at leastone virtual disk 240, a virtual memory system 230, a guest operatingsystem 220 (which may simply be a copy of a conventional operatingsystem), and various virtual devices 280, in which case the guestoperating system (“guest OS”) includes corresponding drivers 224. All ofthe components of the VM may be implemented in software using knowntechniques to emulate the corresponding components of an actualcomputer.

If the VM is properly designed, then it will not be apparent to the userthat any applications 260 running within the VM are running indirectly,that is, via the guest OS and virtual processor. Applications 260running within the VM will act just as they would if run on a “real”computer, except for a decrease in running speed that will be noticeableonly in exceptionally time-critical applications. Executable files willbe accessed by the guest OS from a virtual disk or virtual memory, whichmay simply be portions of an actual physical disk or memory allocated tothat VM. Once an application is installed within the VM, the guest OSretrieves files from the virtual disk just as if they had beenpre-stored as the result of a conventional installation of theapplication. The design and operation of virtual machines is well knownin the field of computer science.

Some interface is usually required between a VM and the underlying hostplatform (in particular, the CPU), which is responsible for actuallyexecuting VM-issued instructions and transferring data to and from theactual memory and storage devices. A common term for this interface is a“virtual machine monitor” (VMM), shown as component 300. A VMM isusually a thin piece of software that runs directly on top of a host, ordirectly on the hardware, and virtualizes the resources of the physicalhost machine. Among other components, the VMM therefore usually includesdevice emulators 330, which may constitute the virtual devices 280 thatthe VM 200 accesses. The interface exported to the VM is then the sameas the hardware interface of the machine, so that the guest OS cannotdetermine the presence of the VMM.

The VMM also usually tracks and either forwards (to some form ofoperating system) or itself schedules and handles all requests by its VMfor machine resources, as well as various faults and interrupts. Amechanism known in the art as an exception or interrupt handler 355 istherefore included in the VMM. As is well known, such aninterrupt/exception handler normally includes an interrupt descriptortable (IDT), or some similar table, which is typically a data structurethat uses information in the interrupt signal to point to an entryaddress for a set of instructions that are to be executed when theinterrupt/exception occurs.

Although the VM (and thus the user of applications running in the VM)cannot usually detect the presence of the VMM, the VMM and the VM may beviewed as together forming a single virtual computer. They are shown inFIG. 1 as separate components for the sake of clarity.

Moreover, the various virtualized hardware components such as thevirtual CPU(s) 210, the virtual memory 230, the virtual disk 240, andthe virtual device(s) 280 are shown as being part of the VM 200 for thesake of conceptual simplicity—in actual implementations these“components” are usually constructs or emulations exported to the VM bythe VMM. For example, the virtual disk 240 is shown as being within theVM 200. This virtual component, which could alternatively be includedamong the virtual devices 280, may in fact be implemented as one of thedevice emulators 330 in the VMM.

The device emulators 330 emulate the system resources for use within theVM. These device emulators will then typically also handle any necessaryconversions between the resources as exported to the VM and the actualphysical resources. One advantage of such an arrangement is that the VMMmay be set up to expose “generic” devices, which facilitate VM migrationand hardware platform-independence. For example, the VMM may be set upwith a device emulator 330 that emulates a standard Small ComputerSystem Interface (SCSI) disk, so that the virtual disk 240 appears tothe VM 200 to be a standard SCSI disk connected to a standard SCSIadapter, whereas the underlying, actual, physical disk 140 may besomething else. In this case, a standard SCSI driver is installed intothe guest OS 220 as one of the drivers 224. The device emulator 330 theninterfaces with the driver 224 and handles disk operations for the VM200. The device emulator 330 then converts the disk operations from theVM 200 to corresponding disk operations for the physical disk 140.

Virtual and Physical Memory

As in most modern computers, the address space of the memory 130 ispartitioned into pages (for example, in the Intel x86 architecture) orother analogous units. Applications then address the memory 130 usingvirtual addresses (VAs), which include virtual page numbers (VPNs). TheVAs are then mapped to physical addresses (PAs) that are used to addressthe physical memory 130. (VAs and PAs have a common offset from a baseaddress, so that only the VPN needs to be converted into a correspondingphysical page number (PPN).) The concepts of VPNs and PPNs, as well asthe way in which the different page numbering schemes are implementedand used, are described in many standard texts, such as “ComputerOrganization and Design: The Hardware/Software Interface,” by David A.Patterson and John L. Hennessy, Morgan Kaufmann Publishers, Inc., SanFrancisco, Calif., 1994, pp. 579-603 (chapter 7.4 “Virtual Memory”).Similar mappings are used in other architectures where relocatability ispossible.

An extra level of addressing indirection is typically implemented invirtualized systems in that a VPN issued by an application 260 in the VM200 is remapped twice in order to determine which page of the hardwarememory is intended. The first mapping is provided by a mapping modulewithin the guest OS 220, which translates the guest VPN (GVPN) into acorresponding guest PPN (GPPN) in the conventional manner. The guest OStherefore “believes” that it is directly addressing the actual hardwarememory, but in fact it is not.

Of course, a valid address to the actual hardware memory must ultimatelybe generated. A memory management module 350, located typically in theVMM 300, therefore performs the second mapping by taking the GPPN issuedby the guest OS 220 and mapping it to a hardware (or “machine”) pagenumber PPN that can be used to address the hardware memory 130. ThisGPPN-to-PPN mapping may instead be done in the main system-levelsoftware layer (such as in a mapping module in a kernel 600, which isdescribed below), depending on the implementation. From the perspectiveof the guest OS, the GVPN and GPPN might be virtual and physical pagenumbers just as they would be if the guest OS were the only OS in thesystem. From the perspective of the system software, however, the GPPNis a page number that is then mapped into the physical memory space ofthe hardware memory as a PPN.

System Software Configurations in Virtualized Systems

In some systems, such as the Workstation product of VMware, Inc., ofPalo Alto, Calif., the VMM is co-resident at system level with a hostoperating system. Both the VMM and the host OS can independently modifythe state of the host processor, but the VMM calls into the host OS viaa driver and a dedicated user-level application to have the host OSperform certain I/O (input/output) operations on behalf of the VM. Thevirtual computer in this configuration is thus fully hosted in that itruns on an existing host hardware platform and together with an existinghost OS.

In other implementations, a dedicated kernel takes the place of andperforms the conventional functions of the host OS, and virtualcomputers run on the kernel. FIG. 1 illustrates a kernel 600 that servesas the system software for several VM/VMM pairs 200/300, . . . ,200N/300N. Compared with a system in which VMMs run directly on thehardware platform, use of a kernel offers greater modularity andfacilitates provision of services that extend across multiple VMs (forexample, for resource management). Compared with the hosted deployment,a kernel may offer greater performance because it can be co-developedwith the VMM and be optimized for the characteristics of a workloadconsisting of VMMs. The ESX Server product of VMware, Inc., has such aconfiguration.

A kernel-based virtualization system of the type illustrated in FIG. 1is described in U.S. patent application Ser. No. 09/877,378 (“ComputerConfiguration for Resource Management in Systems Including a VirtualMachine”), which is incorporated here by reference. The main componentsof this system and aspects of their interaction are, however, outlinedbelow.

At boot-up time, an existing operating system 420 may be at system leveland the kernel 600 may not yet even be operational within the system. Insuch case, one of the functions of the OS 420 may be to make it possibleto load the kernel 600, after which the kernel runs on the nativehardware 100 and manages system resources. In effect, the kernel, onceloaded, displaces the OS 420. Thus, the kernel 600 may be viewed eitheras displacing the OS 420 from the system level and taking this placeitself, or as residing at a “sub-system level.” When interposed betweenthe OS 420 and the hardware 100, the kernel 600 essentially turns the OS420 into an “application,” which has access to system resources onlywhen allowed by the kernel 600. The kernel then schedules the OS 420 asif it were any other component that needs to use system resources.

The OS 420 may also be included to allow applications unrelated tovirtualization to run; for example, a system administrator may need suchapplications to monitor the hardware 100 or to perform otheradministrative routines. The OS 420 may thus be viewed as a “console” OS(COS) or a “service console,” which is analogous to “service processor”hardware for performing setup and diagnostic functions. In suchimplementations, the kernel 600 preferably also includes a remoteprocedure call (RPC) mechanism to enable communication between, forexample, the VMM 300 and any applications 430 installed to run on theCOS 420.

Actions

In kernel-based systems such as the one illustrated in FIG. 1, theremust be some way for the kernel 600 to communicate with the VMM 300. Ingeneral, the VMM 300 can call into the kernel 600 but the kernel cannotcall directly into the VMM. The conventional technique for overcomingthis is for the kernel to post “actions” (requests for the VMM to dosomething) on an action queue stored in memory 130. As part of the VMMcode, the VMM looks at this queue periodically, and always after itreturns from a kernel call and also before it resumes a VM. One typicalaction is the “raise interrupt” action: If the VMM sees this action itwill raise an interrupt to the VM 200 in the conventional manner.

As is known, for example, from U.S. Pat. No. 6,397,242 (Devine, et al.,28 May 2002), some virtualization systems allow VM instructions to rundirectly (in “direct execution”) on the hardware CPU(s) when possible.When necessary, however, VM execution is switched to the technique knownas “binary translation,” during which the VM is running in the VMM. Inany systems where the VM is running in direct execution when it becomesnecessary for the VMM to check actions, the kernel must interrupt theVMM so that it will stop executing VM instructions and check its actionqueue. This may be done using known programming techniques.

Worlds

The kernel 600 handles not only the various VMM/VMs, but also any otherapplications running on the kernel, as well as the COS 420, as entitiesthat can be separately scheduled on the hardware CPU(s) 110. In thisdisclosure, each schedulable entity is referred to as a “world,” whichcontains a thread of control, an address space, machine memory, andhandles to the various device objects that it is accessing. Worlds arestored in a portion of the memory space controlled by the kernel. Morespecifically, the worlds are controlled by a world manager, representedin FIG. 1 within the kernel 600 as module 612. Each world also has itsown task structure, and usually also a data structure for storing thehardware state currently associated with the respective world.

There will usually be different types of worlds: 1) system worlds, whichare used for idle worlds, one per CPU, and one or more helper worlds andother system worlds that perform tasks that, for example, need to bedone asynchronously; 2) a console world, which is a special world thatruns in the kernel and is associated with the COS 420; and 3) virtualmachine worlds.

In the preferred embodiment, worlds generally run at the most-privilegedlevel (for example, in a system with the Intel x86 architecture, thiswill be level CPL0), that is, with full rights to invoke any privilegedCPU operations. A VMM, which, along with its VM, constitutes a separateworld, therefore may use these privileged instructions to allow it torun its associated VM so that it performs just like a corresponding“real” computer, even with respect to privileged operations. User-levelworlds may also be implemented, however, to isolate untrusted code toprevent any failure in the untrusted code from affecting the rest of thesystem.

Switching Worlds

When the world that is running on a particular CPU (which may be theonly one) is preempted by or yields to another world, then a worldswitch has to occur. A world switch involves saving the context of thecurrent world and restoring the context of the new world such that thenew world can begin executing where it left off the last time that itwas running.

The first part of the world switch procedure that is carried out by thekernel is that the current world's state is saved in a data structurethat is stored in the kernel's data area. Assuming the common case of anunderlying Intel x86 architecture, the state that is saved willtypically include: 1) the exception flags register; 2) general purposeregisters; 3) segment registers; 4) the instruction pointer (EIP)register; 5) the local descriptor table register; 6) the task register;7) debug registers; 8) control registers; 9) the interrupt descriptortable register; 10) the global descriptor table register; and 11) thefloating point state. Similar state information will need to be saved insystems with other hardware architectures.

After the state of the current world is saved, the state of the newworld can be restored. During the process of restoring the new world'sstate, no exceptions are allowed to take place because, if they did, thestate of the new world would be inconsistent upon restoration of thestate. The same state that was saved is therefore restored. The laststep in the world switch procedure is restoring the new world's codesegment and instruction pointer (EIP) registers.

When worlds are initially created, the saved state area for the world isinitialized to contain the proper information such that when the systemswitches to that world, then enough of its state is restored to enablethe world to start running. The EIP is therefore set to the address of aspecial world start function. Thus, when a running world switches to anew world that has never run before, the act of restoring the EIPregister will cause the world to begin executing in the world startfunction.

Switching from and to the COS world requires additional steps, which aredescribed in U.S. patent application Ser. No. 09/877,378, mentionedabove. Understanding the details of this process is not necessary forunderstanding the present invention, however, so further discussion isomitted.

Memory Management in Kernel-Based System

The kernel 600 includes a memory management module 616 that manages allmachine memory that is not allocated exclusively to the COS 420. Whenthe kernel 600 is loaded, the information about the maximum amount ofmemory available on the machine is available to the kernel, as well asinformation about how much of it is being used by the COS. Part of themachine memory is used for the kernel 600 itself and the rest is usedfor the virtual machine worlds.

Virtual machine worlds use machine memory for two purposes. First,memory is used to back portions of each world's memory region, that is,to store code, data, stacks, etc., in the VMM page table. For example,the code and data for the VMM 300 is backed by machine memory allocatedby the kernel 600. Second, memory is used for the guest memory of thevirtual machine. The memory management module may include any algorithmsfor dynamically allocating memory among the different VM's 200.

Interrupt and Exception Handling in Kernel-Based Systems

Interrupt and exception handling is related to the concept of “worlds”described above. As mentioned above, one aspect of switching worlds ischanging various descriptor tables. One of the descriptor tables that isloaded when a new world is to be run is the new world's IDT. The kernel600 therefore preferably also includes an interrupt/exception handler655 that is able to intercept and handle (using a corresponding IDT inthe conventional manner) interrupts and exceptions for all devices onthe machine. When the VMM world is running, whichever IDT was previouslyloaded is replaced by the VMM's IDT, such that the VMM will handle allinterrupts and exceptions.

The VMM will handle some interrupts and exceptions completely on itsown. For other interrupts/exceptions, it will be either necessary or atleast more efficient for the VMM to call the kernel to have the kerneleither handle the interrupts/exceptions itself, or to forward them tosome other sub-system such as the COS. One example of an interrupt thatthe VMM can handle completely on its own, with no call to the kernel, isa check-action IPI (inter-processor interrupt). One example of when theVMM preferably calls the kernel, which then forwards an interrupt to theCOS, would be where the interrupt involves devices such as a mouse,which is typically controlled by the COS. The VMM may forward stillother interrupts to the VM.

Device Access in Kernel-Based System

In the preferred embodiment of the invention, the kernel 600 isresponsible for providing access to all devices on the physical machine.In addition to other modules that the designer may choose to load ontothe system for access by the kernel, the kernel will therefore typicallyload conventional drivers as needed to control access to devices.Accordingly, FIG. 1 shows a module 610 containing loadable kernelmodules and drivers. The kernel 600 may interface with the loadablemodules and drivers in a conventional manner, using an applicationprogram interface (API) or similar interface.

Kernel File System

In the ESX Server product of VMware, Inc., the kernel 600 includes afast, simple file system, referred to here as the VM kernel file system(VMFS), that has proven itself to be particularly efficient for storingvirtual disks 240, which typically comprise a small number of large (atleast 1 GB) files. By using very large file system blocks, the filesystem is able to keep the amount of metadata (that is, the data thatindicates where data blocks are stored on disk) needed to access all ofthe data in a file to an arbitrarily small size. This allows all of themetadata to be cached in main memory so that all file system reads andwrites can be done without any extra metadata reads or writes.

The VMFS in ESX Server may take up only a single disk partition, or itmay span multiple partitions or LUNs (Logical Unit Numbers). When it iscreated, it sets aside space for the file system descriptor, space forfile descriptor information, including the file name, space for blockallocation information, and space for block pointer blocks. The vastmajority of the partition's space is used for data blocks, whose size isset when the file system is created. The larger the partition size, thelarger the block size should be in order to minimize the size of themetadata.

As mentioned earlier, the main advantage of the VMFS is that it ensuresthat all metadata may be cached in high-speed, main system memory. Thiscan be done by using large data block sizes, with small block pointers.Since virtual disks are usually at least one gigabyte in size, usinglarge block sizes on the order of 64 Megabytes will cause virtually nowasted disk space and all metadata for the virtual disk can be cachedsimultaneously in system memory.

Besides being able to always keep file metadata cached in memory, theother key to high performance file I/O is to reduce the number ofmetadata updates. Note that the only reason why the VMFS metadata willneed to be updated is if a file is created or destroyed, or if itchanges in size. Since these files are used primarily for virtual disks(or, for example, for copy-on-write redo logs), files are not oftencreated or destroyed. Moreover, because virtual disks are usually fixedin size upon creation, the file size of a virtual disk does not usuallychange. In order to reduce the number of metadata updates on a virtualdisk to zero, the system may therefore preallocate all data blocks forvirtual disks when the file is created.

Checkpointing

A prior patent application owned by the assignee of this applicationdescribes, in a section labeled “Description of the Related Art,”several different types of checkpointing. Specifically, U.S. patentapplication Ser. No. 09/497,978, entitled “Encapsulated Computer System”(“the '978 application”), which is incorporated here by reference,describes transactional disks, file system checkpointing, systemcheckpointing, and application/process-level checkpointing. Each ofthese techniques provides certain benefits to a computer user, such asthe ability to at least partially recover from certain errors or systemfailures. However, each of these techniques also has significantlimitations, several of which are described in the '978 application. Forexample, these techniques generally don't provide checkpointing for acomplete, standard computer system.

In contrast, the '978 application discloses a system and method forextracting the entire state of a computer system as a whole, not just ofsome portion of the memory, which enables complete restoration of thesystem to any point in its processing without requiring any applicationor operating system intervention, or any specialized or particularsystem software or hardware architecture. The preferred embodimentdescribed in the '978 application involves a VMM that virtualizes anentire computer system, and the VMM is able to access and store theentire state of the VM. To store a checkpoint, execution of the VM isinterrupted and its operation is suspended. The VMM then extracts andsaves to storage the total machine state of the VM, including all memorysectors, pages, blocks, or units, and indices and addresses allocated tothe current VM, the contents of all virtualized hardware registers, thesettings for all virtualized drivers and peripherals, etc., that arestored in any storage device and that are necessary and sufficient that,when loaded into the physical system in the proper locations, cause theVM to proceed with processing in an identical manner. After an entiremachine state is saved, subsequent checkpoints may be created by keepinga log of changes that have been made to the machine state since a priorcheckpoint, instead of saving the entire machine state at the subsequentcheckpoint. In the preferred embodiment, when a subsequent checkpoint isstored, portions of the machine state that are small or that are likelyto be entirely changed may be stored in their entirety, while forportions of the machine state that are large and that change slowly alog may be kept of the changes to the machine state.

The invention disclosed in the '978 application provides many advantagesover the prior art. For example, saving the entire state of a complete,standard computer system facilitates complete system recovery from awide variety of errors or failures, without having to modify thecomputer system to enable checkpointing. However, the invention of the'978 application still has a significant limitation. Namely, the methoddisclosed in the '978 application requires a substantial pause in theexecution of the computer system to save the checkpoint. Such a pause inexecution is unacceptable for many computer system implementations.

For example, suppose a commercial server application, such as a webserver or a database server, is hosted on a conventional server computersystem. Many such applications use relatively large amounts of systemmemory, such as 4 gigabytes of memory. Such a commercial serverapplication may be executed within a VM, and the invention of the '978application may be used to generate checkpoints for the VM, includingthe server application. To store a checkpoint according to the method ofthe '978 application, the operation of the VM is suspended while themachine state, including the system memory, is saved to persistentstorage. Saving such large amounts of memory to persistent storage takesmany seconds. In many implementations, suspending such a commercialserver application for many seconds to store a checkpoint would simplynot be tolerable, or would at least be undesirable. Thus, a system andmethod are needed for generating checkpoints for a computer system,where generating the checkpoint does not unduly interfere with theongoing operation of the computer system.

SUMMARY OF THE INVENTION

One embodiment of the invention comprises a method for generating acheckpoint for a virtual machine (VM) in a virtual computer system. TheVM uses a virtual disk and a set of VM memory. The method comprises:maintaining, in an unmodified state, the contents of the virtual disk atthe time for which the checkpoint is generated, while allowing the VM tocontinue using the virtual disk; saving substantially all of the devicestate of the VM, at the time for which the checkpoint is generated, to acheckpoint data store; and saving the set of VM memory, at the time forwhich the checkpoint is generated, to the checkpoint data store. Thestep of saving the set of VM memory comprises: marking the set of VMmemory as copy-on-write (COW), the set of VM memory constitutingoriginal VM memory; allowing the VM to continue using the VM memory;responding to memory COW faults related to the VM memory by generatingcopies of the original VM memory for read and write use by the VM; andsaving the original VM memory to the checkpoint data store.

In another embodiment of the invention, the execution of the VM isstopped while the VM memory is marked COW. In another embodiment, thevirtual disk is initially mapped to a parent disk file on a physicaldisk and the step of maintaining, in an unmodified state, the contentsof the virtual disk comprises creating a copy-on-write (COW) disk filepointing to the parent disk file and mapping the virtual disk to the COWdisk file. In another embodiment, the step of saving the device state ofthe VM to the checkpoint data store comprises saving the device state tomemory while the VM is not executing and copying the device state frommemory to the checkpoint data store after the VM has resumed execution.

Another embodiment of the invention also comprises a method forgenerating a checkpoint for a virtual machine (VM) in a virtual computersystem. Again, the VM uses a virtual disk and a set of VM memory. Inthis embodiment, the method comprises: maintaining, in an unmodifiedstate, the contents of the virtual disk at the time for which thecheckpoint is generated, while allowing the VM to continue using thevirtual disk, the unmodified contents of the virtual disk constituting acheckpointed virtual disk, and the contents of the virtual disk used bythe VM constituting an ongoing virtual disk; saving substantially all ofthe device state of the VM, at the time for which the checkpoint isgenerated, to a checkpoint data store; saving the contents of the VMmemory, at the time for which the checkpoint is generated, to thecheckpoint data store, and allowing the VM to continue using the VMmemory, the contents of the VM memory saved to the checkpoint data storeconstituting a checkpointed VM memory, and the contents of the VM memoryas used by the VM constituting an ongoing VM memory; and allowing the VMto execute during at least a part of the time during which thecheckpoint is being generated, and ensuring that the results of anypending disk writes are applied to both the checkpointed virtual diskand the ongoing virtual disk, that the results of any new disk writesare applied to the ongoing virtual disk, but not to the checkpointedvirtual disk, that the results of any pending disk reads are applied toboth the checkpointed VM memory and the ongoing VM memory, and that theresults of any new disk reads are applied to the ongoing VM memory, butnot to the checkpointed VM memory.

In another embodiment of the invention, the step of saving the contentsof the VM memory to the checkpoint data store comprises: marking the setof VM memory as copy-on-write (COW), the set of VM memory constitutingoriginal VM memory; allowing the VM to continue using the VM memory;responding to memory COW faults related to the VM memory by generatingcopies of the original VM memory for read and write use by the VM; andsaving the original VM memory to the checkpoint data store. In anotherembodiment, the step of ensuring that the results of any pending diskreads are applied to the ongoing VM memory comprises reissuing anypending disk reads for which the results of the read were directed tooriginal VM memory for which a COW fault has occurred, but directing thereissued disk reads to the corresponding copies of the original VMmemory instead of the original VM memory. In another embodiment, thestep of ensuring that the results of any new disk reads are not appliedto the checkpointed VM memory comprises forcing COW faults for anyoriginal VM memory that would otherwise be affected by the new diskreads. In another embodiment, the virtual disk is initially mapped to aparent disk file on a physical disk and the step of maintaining, in anunmodified state, the contents of the virtual disk comprises creating acopy-on-write (COW) disk file pointing to the parent disk file andmapping the virtual disk to the COW disk file. In still anotherembodiment, the step of ensuring that the results of any pending diskwrites are applied to the ongoing virtual disk comprises, if there is apending disk write to the same COW block group as a subsequent write forwhich a disk COW fault has occurred, delaying responding to the disk COWfault and delaying the subsequent write until the pending disk writecompletes.

Yet another embodiment of the invention also comprises a method forgenerating a checkpoint for a virtual machine (VM) in a virtual computersystem. Here, the VM uses a parent disk file and a set of VM memory. Themethod comprises: (1) creating a copy-on-write (COW) disk file pointingto the parent disk file in use by the VM; (2) stopping the VM, and whilethe VM is stopped: (a) marking the memory of the VM copy-on-write, theVM memory constituting original VM memory, (b) saving substantially allof the device state of the VM to memory, and (c) switching the VM to usethe COW disk file instead of the parent disk file; (3) resumingoperation of the VM; (4) handling disk COW faults to the COW disk file;(5) handling memory COW faults to the original VM memory to generatecopies of the original VM memory for read and write use by the VM; (6)saving the device state from memory to a checkpoint data store; and (7)saving the original VM memory to the checkpoint data store.

In another embodiment of the invention, the method further comprises theparent disk file after any pending disk writes complete, and using thecopy of the parent disk file for the checkpoint. In another embodiment,the COW disk file is committed into the original parent disk file. Inanother embodiment, the step of committing the COW disk file into theoriginal parent disk file comprises creating one or more new COW diskfiles for use by the VM while the COW disk file previously used by theVM is being committed. In another embodiment, the steps of creating theCOW disk file and handling disk COW faults are performed by a datastorage device that is external to the virtual computer system. In otherembodiments, the checkpoint data store may comprise raw data or a filestored in a data storage medium. In other embodiments, the data storagemedium may comprise a disk drive or a memory, such as either ahigh-speed RAM or a flash memory.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 illustrates the main components of a kernel-based, virtualizedcomputer system.

FIG. 2A illustrates the main components of a first embodiment of thisinvention at a first point in time, when a virtual machine is executingprior to the generation of a checkpoint.

FIG. 2B illustrates the main components of the first embodiment at asecond point in time, after the generation of a checkpoint has beeninitiated.

FIG. 2C illustrates the main components of the first embodiment at athird point in time, during the generation of the checkpoint.

FIG. 2D illustrates the main components of the first embodiment at afourth point in time, during the generation of the checkpoint.

FIG. 2E illustrates the main components of the first embodiment at afifth point in time, during the generation of the checkpoint, accordingto a first implementation.

FIG. 2F illustrates the main components of the first embodiment at asixth point in time, during the generation of the checkpoint, accordingto the first implementation.

FIG. 2G illustrates the main components of the first embodiment at aseventh point in time, after the generation of the checkpoint hascompleted, according to the first implementation.

FIG. 2H illustrates the main components of the first embodiment afterthe generation of the checkpoint has completed, according to a secondimplementation.

FIG. 3A illustrates a method that is used in the first embodiment of theinvention to generate a checkpoint.

FIG. 3B illustrates the main components of the virtual computer systemthat are involved in using a physical memory page that is markedcopy-on-write, prior to an attempted write to the physical memory page.

FIG. 3C illustrates the main components of the virtual computer systemthat are involved in using the physical memory page of FIG. 3B, after anattempt is made to write to the physical memory page.

FIG. 3D illustrates a disk write interposed between a pair of diskreads, all involving a first data block.

FIG. 3E illustrates a method that is used in the first embodiment of theinvention to handle an attempted write to a copy-on-write page in memoryor a copy-on-write block of a disk during the generation of acheckpoint.

FIG. 3F illustrates a method that is used in the first embodiment of theinvention to commit a copy-on-write disk file to its parent disk fileduring the generation of a checkpoint.

FIG. 3G illustrates a method that is used in the first embodiment of theinvention to begin executing a virtual machine from a previouslygenerated checkpoint.

FIG. 4A illustrates a subset of the main components of the firstembodiment in the same configuration as illustrated in FIG. 2H.

FIG. 4B illustrates the subset of the main components of the firstembodiment during the generation of a second checkpoint according to thesecond implementation.

FIG. 4C illustrates the subset of the main components of the firstembodiment after the completion of the second checkpoint according tothe second implementation, with the first checkpoint being overwritten.

FIG. 4D illustrates the subset of the main components of the firstembodiment after the completion of the second checkpoint according tothe second implementation, with the first and second checkpoints beingmaintained.

FIG. 5A illustrates the subset of the main components of the firstembodiment during the generation of a second checkpoint according to athird implementation.

FIG. 5B illustrates the subset of the main components of the firstembodiment after the completion of the second checkpoint according tothe third implementation.

FIG. 5C illustrates the subset of the main components of the firstembodiment during the generation of a third checkpoint according to thethird implementation.

FIG. 5D illustrates the subset of the main components of the firstembodiment after the completion of the third checkpoint according to thethird implementation.

FIG. 5E illustrates the subset of the main components of the firstembodiment after the completion of the third checkpoint according to thethird implementation, and after the first checkpoint has beeneliminated.

DETAILED DESCRIPTION

This invention may be implemented in a wide variety of virtual computersystems, based on a wide variety of different physical computer systems.A preferred embodiment of the invention is described in connection witha specific virtual computer system simply as an example of implementingthe invention. The scope of the invention should not be limited to or bythe exemplary implementation. In this case, the virtual computer systemin which a first embodiment is implemented is the system 700 illustratedin FIG. 1, which may be substantially the same as the virtual computersystem described in the '978 application.

FIGS. 2A-2H illustrate selected components of the virtual computersystem 700 of FIG. 1, including illustrating some components in greaterdetail. The components illustrated in these figures are generally thecomponents that are most relevant to implementing this invention. Othercomponents of the system 700 are not illustrated in these figures forsimplicity, but the other components of the system may be assumed. Inparticular, these figures do not illustrate the kernel 600 or theloadable modules and drivers 610, but these components may be assumed.Also, FIGS. 2A-2H only illustrate the single VM 200, but additional VMsmay also be assumed. Each of the components illustrated in the FIGS.2A-2H is substantially the same in all of the figures, except asdescribed below.

At the highest level, FIG. 2A illustrates the VM 200, the VMM 300, thephysical memory 130 and the physical disk 140. The VM 200 includes thevirtual memory 230 and the virtual disk 240. The virtual memory 230 ismapped to a portion of the physical memory 130 by the memory managementmodule 350 within the VMM 300, using any of various known techniques forvirtualizing memory. The virtualization of the physical memory 130 isdescribed in greater detail above. The portion of the physical memory130 to which the virtual memory 230 is mapped is referred to as VMmemory 130A. The physical memory 130 also includes a portion that isallocated for use by the VMM 300. This portion of the physical memory130 is referred to as VMM memory 130B. The VM memory 130A and the VMMmemory 130B each typically comprises a plurality of noncontiguous pageswithin the physical memory 130, although either or both of them mayalternatively be configured to comprise contiguous memory pages. Thevirtual disk 240 is mapped to a portion, or all, of the physical disk140 by the disk emulator 330A within the VMM 300, using any of variousknown techniques for virtualizing disk space. The disk emulator 330A isone of the device emulators 330 illustrated in FIG. 1. As describedabove, using the VMFS, the disk emulator 330A typically stores thevirtual disk 240 in a small number of large files on the physical disk140. The physical disk file that stores the contents of the virtual disk240 is represented in FIG. 2A by a base disk file 140A. Although notshown in the figures for simplicity, the disk emulator 330A also hasaccess to the VM memory 130A for performing data transfers between thephysical disk 140 and the VM memory 130A. For example, in a disk readoperation, the disk emulator 330A reads data from the physical disk 140and writes the data to the VM memory 130A, while in a disk writeoperation, the disk emulator 330A reads data from the VM memory 130A andwrites the data to the physical disk 140.

FIG. 2A also illustrates a checkpoint software unit 342 within the VMM300. The checkpoint software 342 comprises one or more software routinesthat perform checkpointing operations for the VM 200, and possibly forother VMs. For example, the checkpoint software may operate to generatea checkpoint, or it may cause a VM to begin executing from a previouslygenerated checkpoint. The routines that constitute the checkpointsoftware may reside in the VMM 300, the kernel 600, or in other softwareentities, or in a combination of these software entities, depending onthe system configuration. Portions of the checkpoint software may alsoreside within software routines that also perform other functions. Forexample, one or more portions of the checkpoint software may reside inthe memory management module 350 for performing checkpointing functionsrelated to memory management, such as copy-on-write functions. Thecheckpoint software 342 may also or alternatively comprise a stand-alonesoftware entity that interacts with the virtual computer system 700 toperform the checkpointing operations. Alternatively, the checkpointsoftware 342 may be partially implemented within the guest world of thevirtual computer system. For example, the guest OS 220 or some otherguest software entity may support the operation of the checkpointsoftware 342, which is primarily implemented within the virtualizationsoftware. The checkpoint software may take any of a wide variety offorms. Whichever form the software takes, the checkpoint softwarecomprises the software that performs the checkpointing functionsdescribed in this application.

FIG. 2A shows the virtual computer system 700 when it is running priorto the initiation of an operation to generate a checkpoint. Thegeneration of a checkpoint may be initiated automatically within thevirtual computer system 700, such as on a periodic basis; it may beinitiated by some user action, such as an activation of a menu option;or it may be initiated based on some other external stimulus, such asthe detection of a drop in voltage of some power source, for example.

Once a checkpoint generation is initiated, the checkpoint software 342begins running as a new task, process or thread within the virtualcomputer system, or the task becomes active if it was already running.The checkpoint software is executed along with the VM 200 in a commonmultitasking arrangement, and performs the method illustrated in FIG. 3Ato generate the checkpoint. FIGS. 2B-2G illustrate the general state ofthe virtual computer system at different times during and after thegeneration of the checkpoint, according to a first implementation of thefirst embodiment of the invention. FIG. 2H illustrates the general stateof the virtual computer system at the completion of the checkpoint,according to a second implementation of the first embodiment. Changes inthe respective states of the components illustrated in FIGS. 2A-2H aregenerally highlighted in the figures by using bold text and/or thicklines. FIG. 3A illustrates both the first implementation and the secondimplementation of the first embodiment of the invention. The method ofFIG. 3A for generating a checkpoint will now be described, withreference to FIGS. 2A-2H.

FIG. 3A begins at an initial step 800, when the operation to generate acheckpoint is initiated. FIG. 2A illustrates the state of the virtualcomputer system 700 at the step 800. Next, the method of FIG. 3Aproceeds to a step 802. FIG. 2B illustrates the state of the virtualcomputer system 700 at the step 802. At the step 802, the checkpointsoftware 342 creates a new copy-on-write (COW) disk file 140B thatreferences the base disk file 140A. Techniques for creating, using andmaintaining COW files are well known in the art. As an alternative tothis implementation of a COW disk file, a disk-based copy-on-writefunction may be implemented, such as a “snapshot” operation supported bymany SAN systems and NAS (Network-Attached Storage) systems. As shown inparentheses within the block of the VM 200 in the FIG. 2B, the VM isstill running during the step 802, when the COW disk file 140B iscreated. The new COW disk file is shown in FIG. 2B in bold text andthick lines to highlight the fact that the COW disk file is created atthis point in time during the generation of the checkpoint. The thickline from the COW disk file 140B to the base disk file 140A indicatesthat the COW disk file references the base disk file. In other words,according to known copy-on-write techniques, the COW disk file initiallycontains no substantive content; instead, all of the substantive contentfor the COW disk file is contained in the base disk file, and the COWdisk file contains pointers to the actual data in the base disk file.The operation of the COW disk file is described in greater detail below.

After the step 802, the method of FIG. 3A proceeds to a step 804. FIG.2C illustrates changes to the state of the virtual computer system 700from the step 804 through a step 812 of FIG. 3A. First, at the step 804,the execution of the VM 200 is stopped. The VM 200 is simply not givenany execution cycles on the CPU(s) 110. Meanwhile, the checkpointsoftware 342 is still given execution time to continue with the methodof FIG. 3A. In FIG. 2C, the stopped condition of the VM 200 is shown inparentheses, using bold text, within the block of the VM 200.

Next, at a step 806, the VM memory 130A is marked COW, as shown inparentheses, using bold text, within the block for the VM memory 130A inFIG. 2C. COW techniques for memory are also well known in the art.Although the general techniques are preferably modified for use in avirtual computer system, most of the same general principles apply. Theprimary modification relates to the fact that there is an extra level ofaddress indirection in a virtual computer system, as described above.FIGS. 3B and 3C illustrate the COW techniques that are preferably usedin the virtual computer system 700. FIGS. 3B and 3C illustrate the VM200, including a guest application 260 and the guest OS 220; the VMM300, including the memory management module (MMM) 350; and the VM memory130A, including a first physical memory page 130D. FIG. 3C alsoillustrates a second physical memory page 130E within the VM memory130A. FIG. 3B represents the state of the illustrated components whenthe first memory page 130D is marked COW, and before any attempted writeto the page. FIG. 3C represents the changes that are made if an attemptis made to write to the first memory page 130D while it is marked COW.

As shown in FIG. 3B, the application 260 uses a GVPN, GVPN1, in aconventional manner to perform memory reads and writes. The guest OS 220specifies a translation from GVPN1 to GPPN1, which the guest OS believesto be an actual physical memory page. Unlike typical COWimplementations, the guest OS 220 does not mark the GPPN1 as being COW.In fact, the guest OS 220 preferably cannot even detect that any realphysical memory pages are marked COW. As further shown in FIG. 3B, theMMM 350 uses the first memory page 130D to correspond with the GPPN1.Thus, the MMM 350 determines a translation from GPPN1 to PPN1. For thepage table entries or translations that are loaded into a hardware TLB(Translation Look-aside Buffer), whether the translations are loaded byhardware or software, the MMM 350 further determines a translation fromGVPN1 to PPN1.

Now the MMM 350 uses general COW techniques in translating from GPPNs toPPNs, and from GVPNs to PPNs. Thus, the MMM 350 marks the first memorypage 130D as COW. If an attempt is made to write to the first memorypage 130D, such as by the application 260 specifying a write to GVPN1,then a COW fault occurs. In response to the COW fault, the MMM 350 takesthe actions illustrated in FIG. 3C. First, the MMM 350 copies thecontents of the first memory page 130D to the second memory page 130E.Next, the MMM 350 changes the translations for GPPN1 and GVPN1 tospecify the second memory page 130E, instead of the first memory page130D. Thus, the translations loaded into the hardware TLB will indicatea translation from GVPN1 to PPN2. As is common practice in virtualmemory systems, changing a translation that is loaded into the hardwareTLB may require that the TLB be flushed or that an entry in the TLB beinvalidated. The MMM 350 also removes the COW marking on the firstmemory page 130D. The translation maintained by the guest OS 220 for theGVPN1 continues to specify the GPPN1. At this point, if the guestapplication 260 attempts to access its memory page GVPN1, the guest OS220 continues to map the attempted access to the GPPN1. However, the MMM350, and hence the system hardware, now map the attempted access to thesecond memory page 130E, instead of the first memory page 130D. Thefirst memory page 130D will remain unmodified from the point in timewhen it was marked as COW, so that it can be used for the generation ofthe checkpoint, as described further below. Meanwhile, the VM 200 is nowable to read and write to the memory page that it refers to as GVPN1 orGPPN1, using the copied content in the second memory page 130E.

Returning to FIG. 3A, the method proceeds next to a step 808. At thispoint, the checkpoint software 342 copies the state of the VM 200 to theVMM memory 130B, as indicated in FIG. 2C as the device state 130C. Thecontents of the device state 130C will depend on the particularimplementation of the virtual computer system in which the invention isimplemented. The '978 application describes a “total machine state,”which includes the contents of all virtualized hardware registers, thesettings for all virtualized drivers and peripherals, etc., that arestored in any storage device and that are necessary and sufficient that,when loaded into the physical system in the proper locations, cause theVM to proceed with processing in an identical manner; where a “storagedevice” includes any device that is capable of storing data, includingsystem memory, caches, non-volatile memory and mass storage devices suchas hard disks. The device state 130C in this application is the same asthe total machine state of the '978 application, except without the VMmemory and the VM's disk file. According to this invention, the devicestate also includes a list of all “pending” disk operations and networkoperations. A “pending” disk operation is a disk read or write that wasissued to the actual hardware before the VM 200 was stopped at the step804, but for which the hardware has not yet reported completion of theentire request, including a response. A “pending” network operation is anetwork packet that has been issued to the hardware for transmission toan attached computer network, but for which the hardware has not yetreported a completed issuance. Again the saving of the device state 130Cis highlighted in FIG. 2C using thick lines and bolded text.

Next, at a step 810, the checkpoint software 342 changes theconfiguration of the disk emulator 330A, so that the virtual disk 240 isnow mapped to the COW disk file 140B, instead of the base disk file140A. The method for reconfiguring the disk emulator 330A in this mannerdepends on the particular implementation, but it typically involvesupdating certain internal data structures within the emulation layer.Again, this change in the disk virtualization mapping is illustrated inFIG. 2C using a thick line. Now, once the VM 200 begins running again,any attempted access to the virtual disk 240 will be directed to the COWdisk file 140B. The COW disk file will operate in accordance with knowncopy-on-write techniques. Thus, if a write is attempted to a block ofthe COW disk file for which there is a pointer to a corresponding blockof the base disk file, the block of the base disk file is copied to theCOW disk file, and the write is performed on the copy of the block inthe COW disk file. If a write is attempted to a block that alreadyexists in the COW disk file, the write is simply performed to thatblock. Similarly, if a read is attempted to a block that already existsin the COW disk file, the read is simply performed on that block. If aread is attempted to a block of the COW disk file for which there is apointer to a corresponding block of the base disk file, the read isperformed on the corresponding block of the base disk file.

Next, the method of FIG. 3A proceeds to the step 812. At this step, thecheckpoint software 342 begins accounting for possible pending diskoperations. Pending disk operations may take a substantial amount oftime to complete, especially if the VM 200 happened to have issued alarge number of disk operations just before the checkpoint generationwas initiated. As a result, it is generally preferable, according to theinvention, to proceed with the checkpoint generation without having towait for pending disk operations to complete. At the same time, however,it may sometimes be necessary or advantageous to wait for some or alldisk operations to complete.

One object of the invention is to generate a checkpoint for a first VM,which is running when the checkpoint is initiated and continues to runafter the checkpoint is generated, without unduly interfering with theongoing operation of the first VM. One technique of this invention forreducing the interference with the operation of the first VM is toenable the first VM to continue running for much of the time that thecheckpoint is being generated. Generally, at the point in time at whicha checkpoint is initiated, the state of the first VM is frozen andstored to disk, so that, at a later time, it is possible to cause thefirst VM to revert back to the checkpointed state, and resume operationfrom that point. At the same time, it is preferably also possible tocause one or more other VMs to begin execution at the checkpointed stateof the first VM. When a checkpoint is initiated, and the VM for whichthe checkpoint has been initiated continues running, the state of thecontinuing VM generally diverges from the checkpointed state. In thepreferred embodiment, the checkpointed state that is saved to disk issubstantially the same state, or exactly the same state, as would besaved to disk if the VM were stopped upon initiation of the checkpoint,if pending disk operations were permitted to complete and if the entireVM device state were saved to disk, as described in the '978application. At the same time, however, the state of the continuing VMis preferably substantially the same as if no checkpoint had beeninitiated at all, except for an acceptable delay in execution of the VM.

Pending disk operations are typically DMA (Direct Memory Access)operations that are set up by the CPU 110 and that are performed by adifferent hardware device, such as a disk controller. Suppose, forexample, that the CPU 110 issues two separate DMA operations related tothe physical disk 140 just before the generation of a checkpoint isinitiated. Suppose the first disk operation is a read from a first datablock of the base disk file 140A into a first memory page of the VMmemory 130A, and the second disk operation is a write from a secondmemory page of the VM memory 130A into a second data block of the basedisk file 140A. As described above, after the initiation of thecheckpoint generation, the VM memory 130A is marked COW and a COW diskfile 140B is created referencing the base disk file 140A. If a COW faultoccurs on the first memory page of the VM memory 130A, then a copy ofthe first memory page is made for use by the continuing VM, while theoriginal memory page is retained in an unmodified condition for use ingenerating the checkpoint. Similarly, if a COW fault occurs on the datablock of the COW disk file 140B that corresponds with the second datablock of the base disk file 140A, then a copy of the second data blockof the base disk file is made in the COW disk file for use by thecontinuing VM, while the original data block is retained in anunmodified condition for use in generating the checkpoint.

Now the DMA operations were specified in terms of the base disk file140A and the original pages of the VM memory 130A, not in terms of theCOW disk file 140B or in terms of any copies of the VM memory pages thathave resulted from COW faults. For the main embodiment described in thisapplication, the virtual computer system 700 does not include aninput/output memory management unit (IO-MMU) for providing virtualmemory functions for I/O operations. For such systems that do notinclude an IO-MMU, the DMA operations are specified and performedentirely using physical memory addressing. The DMA operations are notsubject to the virtual memory system implemented by the MMM 350. Inparticular, DMA writes to the VM memory 130A will not cause COW faults,even if a write is to a page that is marked COW. As a result, the firstpending disk operation will cause the first data block of the base diskfile 140A to be read into the first memory page of the VM memory 130A,regardless of whether the first memory page is marked COW. Similarly,the second pending disk operation will cause a write from the secondmemory page of the VM memory 130A into the second data block of the basedisk file 140A, regardless of whether the second data block of the basedisk file has yet been copied into the COW disk file as a result of aCOW fault. As a result, as long as the first pending disk operationcompletes before the first memory page of the VM memory 130A is used togenerate the checkpoint, and as long as the second disk operationcompletes before the second data block of the base disk file is used togenerate the checkpoint, then the completion of the first and seconddisk operations will be correctly incorporated into the checkpoint. If aCOW fault does not occur relative to either the first memory page of theVM memory 130A or the second data block of the base disk file 140A, thenthe pending disk operations will also be correctly incorporated into thestate of the continuing VM once the disk operations complete, as thestate of the continuing VM still includes both the first memory page andthe second data block.

When implementing the invention in a system that includes an IO-MMU, aperson of skill in the art will understand how to use the IO-MMU toadvantage in implementing the invention. For example, the IO-MMU may beconfigured to, in effect, trigger a COW memory fault for new disk readoperations that are issued after a checkpoint generation is initiated.In this case, a step 816 of FIG. 3A, which is described below, would notbe required.

If a COW fault occurs relative to the first memory page of the VM memory130A before the first memory page is saved to disk for the checkpoint,then a copy of the first memory page is generated for use by thecontinuing VM. Now if the COW fault occurs before the completion of thefirst pending disk operation, then the first data block from the basedisk file 140A is written into the first memory page of the VM memory130A, which will be used for checkpointing, and not into the copy of thefirst memory page caused by the COW fault, which will be used by thecontinuing VM. Thus, if the COW fault occurs before the pending diskoperation completes, the continuing VM will not see the results of thepending disk operation. This situation can generally be resolved byissuing a third disk operation in which the first data block of the basedisk file is also read into the copy (created in response to the COWfault) of the first memory page of the VM memory. This approach isimplemented in this invention, as described in greater detail belowrelative to a step 815 of FIG. 3A.

Now suppose a slightly different situation occurs, as illustrated inFIG. 3D. FIG. 3D shows the memory 130, including the VM memory 130A,which further includes a first physical memory page 130F, a copy of thefirst memory page 130G and a second physical memory page 130H. FIG. 3Dalso shows the disk 140, including the base disk file 140A, whichfurther includes a first data block 140F.

Now suppose that there is a pending disk read from the first data block140F into the first memory page 130F and a pending disk write from thesecond memory page 130H into the first data block 140F, when acheckpoint generation is initiated. Suppose further that, before thepending disk read completes, a memory write is performed to the firstmemory page 130F, giving rise to a COW fault, so that the copy of thefirst memory page 130G is created, as shown by a reference number 1 inFIG. 3D. Suppose that the pending disk read completes next, as shown bya reference number 2 in FIG. 3D. The pending disk read writes the datafrom the first data block 140F into the first memory page 130F, and notinto the copy of the first memory page 130G. Now, in an attempt toensure that the continuing VM sees the results of the pending disk readoperation, a second disk read is issued to write the data from the firstdata block 140F into the copy of the first memory page 130G. However,suppose that the pending disk write completes next, as shown by areference number 3 in FIG. 3D. The disk write from the second memorypage 130H to the first disk block 140F modifies the contents of thefirst data block 140F. Next, the disk read from the first disk block140F to the copy of the first memory page 130G completes, as shown by areference number 4 in FIG. 3D. The modified contents of the first datablock 140F are written into the copy of the first memory page 130G,instead of the original contents. Thus, the continuing VM will not seethe correct contents in the copy of the first memory page 130G.

This potential problem is resolved in the preferred embodiment in thestep 812. At the step 812, the checkpoint software 342 checks allpending disk operations to see if there is a pending disk read of a datablock, followed by a pending disk write to the same data block. If thissituation exists, the method of FIG. 3A is delayed until all pendingdisk operations complete. This way, there will be no COW faults beforethe disk operations complete, and all of the pending disk operationswill be correctly incorporated into both the checkpointed state and thestate of the continuing VM.

Other resolutions for this situation are also possible. For example, thecheckpoint software 342 could wait for a COW fault to occur on a memorypage of the VM memory 130A. In response to such a COW fault, thecheckpoint software 342 could determine if there is a pending disk readinto the same memory page. If there is no such pending disk read, theresponse to the COW fault may proceed in a normal manner. On the otherhand, if there is a pending disk read to the memory page at which theCOW fault occurred, then the continuing VM may be suspended until thedisk read completes. Once the disk read completes, the response to theCOW fault may proceed in a normal manner. The copy of the memory pagecreated by the COW fault will contain the data from the disk read,ensuring that the results of the disk read are correctly incorporatedinto the state of the continuing VM. However, in a typical virtualcomputer system, having a pending disk read into the same memory page onwhich a COW fault has occurred is much more likely to occur than havinga pending disk read of a block followed by a pending disk write to thesame block. Thus, if we consider a VM operating over a significantperiod of time and generating a significant number of checkpoints, thefirst solution described above will generally have a much smaller impacton the operation of the continuing VM than the second solution.

On a related topic, if the VM 200 is connected to a network, such asthrough the network interface 180, there may also be pending networkoperations, or network packets that were issued to the actual hardwareprior to the initiation of the checkpoint, but which have not yet beensent, or network packets that have been received by the hardware, butnot yet reported to software. Such pending network operations arepreferably handled differently from pending disk operations. The guestOS 220 and/or the guest applications 260 may have adverse reactions tothe failure of a disk operation to complete. However, computer systemsare generally designed to be quite tolerant of failed networkoperations. Thus, the approach taken in the preferred embodiment of theinvention is to simply indicate that all pending network operations havecompleted, for both the continuing VM and any VM that is resumed at alater time from the checkpointed state. If either the continuing VM or aresumed VM detects that a data packet was not received by an intendedrecipient, then the VM will simply resend the data packet. Similarly, ifanother system detects that a data packet that it sent to the virtualcomputer system 700 was not received by either the continuing VM or aresumed VM, then the other system must resend the data packet.

Returning to the method of FIG. 3A, after the step 812, the methodproceeds to a step 814. FIG. 2D illustrates changes to the state of thevirtual computer system 700 from the step 814 through a step 824 of FIG.3A. First, at the step 814, the execution of the VM 200 is resumed, asshown in parentheses, using bolded text, within the box of the VM 200 ofFIG. 2D. At this point, the VM 200 is again allowed to execute, alongwith the checkpoint software 342, like any two processes in a standardmultitasking operating system. The relative priorities of the VM 200 andthe checkpoint software 342 may vary depending on the relativeimportance of minimizing the interference with the ongoing operation ofthe VM 200 caused by the checkpoint generation and the speed at whichthe checkpoints must be generated or are preferred to be generated.

After the step 814, the method of FIG. 3A proceeds to the step 815. Ifthe checkpoint software 342 delayed at the step 812 to wait for allpending disk operations to complete, then the checkpoint software passesstraight through the step 815. If there was no delay at the step 812,then the step 815 is performed on an ongoing basis during the generationof the checkpoint. At the step 815, the checkpoint software effectivelyreissues certain of the pending disk reads, but with the data that isread from the disk being directed to memory pages of the continuing VM.As described above, if a COW fault occurs on a memory page of the VMmemory 130A into which a pending disk read is to transfer data, the datawill be transferred into the original memory page, instead of the copyof the original memory page. The continuing VM will not see the effectsof this pending disk read. Therefore, at the step 815, unless there wasa delay at the step 812, as each pending disk read completes thattransferred data into a memory page for which a COW fault has occurred,the disk read is reissued, but with the data being transferred this timefrom the original disk block into the copy of the original memory page.Also, the continuing VM is not notified of the completion of theoriginal disk read that transferred data into the original page, but thecontinuing VM is notified of the completion of the reissued disk read.

Next, the step 816 shows another step that is performed on an ongoingbasis during the generation of the checkpoint. For this step, thecheckpoint software 342 responds to any new disk reads generated by theVM 200. To perform the step 816, a portion of the checkpoint software342 may be implemented within the disk emulator 330A. As describedabove, disk reads are typically DMA operations, which are not subject tothe virtual memory system implemented by the MMM 350, including the COWprovisions. Suppose for example, the VM 200 issues a disk read into afirst memory page of the VM memory 130A. Suppose further that no COWfault has occurred relative to this memory page, so that it is stillmarked COW, and there is no copy of the memory page. The disk readoperation would write data into the first memory page without triggeringthe COW provisions. But this first memory page is still the originalcopy of the memory page, which should not be modified until it is usedfor the checkpoint generation. The disk read, if allowed to completenormally, would change the checkpointed state from the state at whichthe checkpoint was initiated. To remedy this situation, the checkpointsoftware 342 forces a COW fault on the first memory page before allowingthe disk read to issue. In response to the COW fault, a copy of thememory page is created and the address mapping for the correspondingGVPN is changed to the PPN of the copied memory page, as described aboverelative to FIGS. 3B and 3C. The disk read is now issued to read thedata into the copy of the first memory page, instead of reading the datainto the first memory page itself.

The next step of the method, step 818, also represents an ongoing step.As the checkpoint is being generated, the checkpoint software 342responds to any COW faults related either to the VM memory 130A or theCOW disk file 140B. A method for responding to these COW faults isillustrated in FIG. 3E. The method begins at a step 840. Next, at a step842, the checkpoint software determines whether the COW fault relates tothe VM memory 130A or to the COW disk file 140B. If the fault resultedfrom an attempted write to the VM memory 130A, the method proceeds to astep 844. The portion of the method from the step 844 to a step 850 wasdescribed above in connection with FIGS. 3B and 3C. At the step 844, thecheckpoint software copies a first memory page (PPN1), the page forwhich the COW fault occurred, into a second memory page (PPN2). Next, ata step 846, the checkpoint software changes the mapping for the GVPN andthe GPPN that have been mapped to the first memory page, PPN1, over tothe second memory page, PPN2, so that the second memory page, PPN2, willbe used by the VM 200 for any subsequent memory operations. As indicatedat a step 848, the first memory page, PPN1 will be copied to acheckpoint file as part of the checkpointed state. Next, at the step850, the COW marking is removed from the first memory page, PPN1.

FIG. 2D shows three different types of memory pages that may existwithin the VM memory 130A. For memory pages for which a COW fault hasnot yet occurred, the unmodified, original memory pages are shown as“Original, uncopied” memory pages 130I. FIG. 2D shows that these memorypages are marked COW. When a COW fault occurs on an unmodified, originalmemory page, the original memory page is copied, resulting in a stillunmodified, original memory page and a copy of the original memory page.The unmodified, original memory pages for which a COW fault has occurredare shown as “Original, copied” memory pages 130J. FIG. 2D shows thatthese memory pages are no longer marked COW. The copies of the originalmemory pages 130J are shown as “copies” 130K. Thus, before the aboveexample, the first memory page PPN1 would be an original, uncopiedmemory page 130I, while after the above example, the first memory pagePPN1 would be an original, copied memory page 130J and the second memorypage PPN2 would be a copy 130K.

In the case of a COW fault resulting from an attempted write to the COWdisk file 140B, the method of FIG. 3E proceeds from the step 842 to astep 854. Now a distinction should be drawn between the size of a datablock of the physical disk 140 and the size of the granularity used inimplementing the COW disk functions. The size of a data block for aphysical disk is generally defined as the smallest set of data that maybe written to the disk in a single write operation. In this case, thegranularity for COW disk functions cannot be smaller than the data blocksize. Thus, the size of the granularity for COW disk functions istypically greater than or equal to the size of a data block and istypically an integer multiple of the size of a data block. Also, ofcourse, boundaries used for COW disk functions are also generallyaligned on data block boundaries. Thus, for example, suppose that thephysical disk 140 has a data block size of 512 bytes and the COW diskfunctions are implemented with a granularity of 2048 bytes, so that theCOW disk functions operate on groups of four data blocks. Such a groupof data blocks on which the COW disk functions operate will be referredto as a COW block group.

Now suppose the VM has attempted a write to a data block for which theCOW disk file contains a pointer to a first data block in the base diskfile 140A. At the step 854, the checkpoint software 342 checks to see ifthere is also a pending disk write to the COW block group containing thefirst data block, from before the checkpoint generation was initiated,which has not yet completed. If there is such a pending disk write, thenthe pending response to the COW fault and the new disk write are delayeduntil the pending disk write completes to the COW block group. Thisensures that the data of the pending disk write will be seen by thecontinuing VM once the copy of the COW block group is made. Having a newdisk write to the same COW block group as a pending disk write is notlikely to occur often, especially if the size of the granularity for theCOW disk is small. In fact, if the size of the granularity for the COWdisk is the same size as the size of a data block, then the step 854 isunnecessary. During the delay that may be imposed by this step 854, theexecution of the VM 200 and/or the generation of the checkpoint by thecheckpoint software may generally proceed.

After the step 854, the method of FIG. 3E proceeds to a step 856. Atthis step, the COW block group of the base disk file containing thefirst disk block is copied to the corresponding disk blocks of the COWdisk file, in place of the pointer to the first disk block. Next, a step858 indicates that the copy in the COW disk file is used by the VM 200.Next, a step 860 indicates that the first disk block of the base diskfile is used for the generation of the checkpoint. Instead ofimplementing the steps 856 to 860 within the virtual computer system700, the disk COW functions may alternatively be provided by an externaldata storage system, for example, such as in the case of the snapshotoperation mentioned above, which is provided by many SAN systems and NASsystems. Otherwise, if the step 854 were not included in this method,the COW block group of the base disk file containing the first diskblock may be copied before the pending disk write completes. The pendingdisk write would be addressed to the COW block group of the base diskfile, and not to the copy of the COW block group in the COW disk file.As a result, the checkpointed state would see the result of the pendingdisk write in the base disk file, but the continuing VM would not seethe result of the pending disk write in the COW disk file. The step 854delays the copying of the COW block group until after the pending diskwrite completes to ensure that both the checkpointed state and thecontinuing VM see the result of the pending disk write.

Returning to the description of FIG. 3A, after the step 818, the methodproceeds to a step 820. At this step, the checkpoint software 342creates a checkpoint file 142 on the physical disk 140. The checkpointsoftware then copies the device state 130C from the VMM memory 130B intothe checkpoint file 142 to create a copy of the device state 142B. Theactions taken during the step 820 are also highlighted in FIG. 2D withthick lines and bolded text.

In other embodiments, the checkpoint file 142 may be stored in any ofvarious other forms of data storage, such as in RAM on the virtualcomputer system 700, in RAM on a remote device or system, in nonvolatileflash memory, or in a tape storage system. For example, the checkpointfile 142 may be stored in RAM to provide the capability of resumingexecution of a VM from the checkpointed state very quickly. Also, thedata that is stored in the checkpoint file 142 may alternatively bestored as raw data to a partition or LUN (logical unit number) of alocal disk or a remote storage system, separate from any file system.Also, the data of the checkpoint file 142, or the raw data inalternative embodiments, may also be compressed and/or encrypted.

As described above, the relative priorities of the VM 200 and thecheckpoint software 342 may vary depending on the relative importance ofexecuting the VM 200 with minimal interference and generating thecheckpoint in a timely manner. The relative priorities may also bemodified, based on various criteria. For example, the priority of the VM200 may initially be set high relative to the priority of the checkpointsoftware. With these priorities, if the VM 200 is relatively active, thecheckpoint software may not get enough execution cycles to copy thedevice state 130C to the checkpoint file 142, or otherwise complete thecheckpoint. Then, if the time that has elapsed since the checkpoint wasinitiated surpasses one or more preset time thresholds, the priority ofthe checkpoint software may be increased relative to the VM 200, causingthe checkpointing process to progress more quickly. In this manner, theinterference with the operation of the VM 200 is minimized as much aspossible, while ensuring that the checkpoint is completed in a timelymanner.

Various other factors may also affect overall system performance. Forexample, having too many memory COW faults may consume excessive amountsof memory in the copies 130K of the VM memory pages, which could causethe system to run out of memory required for other purposes, or it maycause the system to excessively swap virtual memory pages between memoryand the physical disk in the known “disk thrashing” situation. Suchsituations may be avoided or mitigated by monitoring the quantity ofmemory COW faults that occur and slowing down the execution of the VM200 to limit the number of memory COW faults. For example, the executioncycles given to the VM 200 may be cut back once the number of memory COWfaults occurring in every second of execution of the VM 200 reaches somethreshold value.

Next, the method of FIG. 3A proceeds to a step 822. At this step, thecheckpoint software 342 waits until all pending disk reads complete, ifthey have not already completed, before proceeding to the next step.Other software processes, including the continuing VM, may continueexecuting while the checkpoint software is waiting for the pending diskreads to complete. Next, the method proceeds to the step 824. At thisstep, the checkpoint software copies the unmodified pages of the VMmemory 130A to the checkpoint file 142, to create a copy of the VMmemory 142C. For memory pages for which a COW fault has occurred, thecheckpoint software copies the original memory pages to the checkpointfile, not the copied pages. After such a memory page has been copied,the page may be freed for use for some other purpose. For memory pagesfor which a COW fault has not occurred, the checkpoint software copiesthe original pages to the checkpoint file. The step of copying the VMmemory 130A to the checkpoint file 142 is also highlighted in FIG. 2Dusing thick lines and bolded text. The possible delay imposed at thestep 822 is implemented to ensure that the results of all pending diskreads are incorporated into the original memory pages of the VM memory130A before the memory pages are captured in the checkpointed state inthe VM memory copy 142C.

Next, the method of FIG. 3A proceeds to a step 828. FIG. 2E illustrateschanges to the state of the virtual computer system 700 from the step828 through a step 832 of FIG. 3A. First, at the step 828, any COWmarkings remaining on the memory pages of the VM memory 130A areremoved, as indicated in parentheses, using bolded text, within the boxof the VM memory 130A of FIG. 2E. Next, the method of FIG. 3A proceedsto an optional step 830. If the optional step 830 is performed, alongwith a second optional step 834, then a first implementation of thefirst embodiment of the invention is realized. If neither of theoptional steps 830 and 834 is performed, then a second implementation ofthe first embodiment is realized. The steps 830 and 834 are indicatedwith dashed lines to indicate that they are optional. At the step 830,the checkpoint software 342 waits for any pending disk writes tocomplete, if they have not already completed. Next, the checkpointsoftware copies the base disk file 140A to a new checkpoint disk file140C, as indicated in thick lines and bolded text in the FIG. 2E. Thiscopy of the base disk file may be made, for example, using a hardwaremirroring or copying function that is available from many data storagesystems, such as a disk-to-disk copy function or a disk array to diskarray copy function. This step is performed in a manner that is similarto the step 824 described above for saving the VM memory 130A to thecheckpoint file 142. The possible delay before copying the base diskfile is implemented to ensure that the results of any pending diskwrites are incorporated into the base disk file 140A, before the basedisk file is copied into the checkpoint disk file 140C, to ensure thatthe results of the pending disk writes are incorporated into thecheckpointed state.

Next, at a step 832, the checkpoint software 342 adds a disk filepointer 142A to the checkpoint file 142 pointing to the checkpoint diskfile 140C, as highlighted in FIG. 2E using thick lines and bolded text.The disk file pointer is added to the checkpoint file so that the entirecheckpointed state may be determined by reference to the checkpointfile. The contents of the checkpoint file 142 and whatever file ispointed to by the disk file pointer 142A together constitute the entirecheckpointed state. In this case, the checkpointed state consists of thecheckpoint file 142 and the checkpoint disk file 140C.

Next, the method of FIG. 3A proceeds to a step 834. FIG. 2F illustrateschanges to the state of the virtual computer system 700 during the step834 of FIG. 3A. At the step 834, the COW disk file 140B is committedinto the base disk file 140A. This step is performed according to amethod illustrated in FIG. 3F. The method of FIG. 3F begins at aninitial step 870. Next, the checkpoint software 342 determines whetherthe COW disk file 140B is small enough to be immediately committed. Asdescribed in greater detail below, the VM 200 is stopped while the COWdisk file is ultimately committed into the base disk file 140A. If theCOW disk file 140B is too large, then the operation of the VM 200 isinterrupted for too long a period while the COW disk file is committed.Thus, a threshold value for the size of the COW disk file may beestablished based on system performance requirements. If the COW diskfile is smaller than the threshold value, then the method proceeds to astep 880; otherwise, the method proceeds to a step 874.

At the step 874, the checkpoint software 342 creates a second COW diskfile that references the original COW disk file 140B. Next, at a step876, the checkpoint software atomically changes the mapping of the diskemulator 330A, so that the virtual disk 240 is mapped to the second COWdisk file, instead of to the original COW disk file. Next, at a step878, the original COW disk file 140B is committed to its parent, thebase disk file 140A. The second COW disk file is created for use by theVM 200, so that the original COW disk file can be committed to the basedisk file without having to stop the execution of the VM. After the step878, the method of FIG. 3F returns to the step 872, so that the steps872, 874, 876 and 878 form a loop, which may be executed multiple times.After executing the loop a first time, the original COW disk file 140Bhas been committed to the base disk file 140A. Now the second COW diskfile references the base disk file 140A. The second COW disk file shouldbe smaller than the original COW disk file was because it has only beenoperating for the amount of time necessary for the checkpoint softwareto commit the original COW disk file. Now, at the step 872, thecheckpoint software determines whether the second COW disk file is smallenough to be directly committed. If not, then the loop may be performedagain, with the creation of a third COW disk file referencing the secondCOW disk file, so that the second COW disk file may be committed to thebase disk file. This loop may be performed as many times as necessary,until, at some point, the newest COW disk file will be small enough todirectly commit to the base disk file 140A. At this point, the method ofFIG. 3F proceeds to a step 880.

At the step 880, the checkpoint software 342 stops the execution of theVM 200. Next, at a step 882, the checkpoint software commits the currentCOW disk file into the base disk file 140A. Next, at a step 884, thecheckpoint software changes the mapping of the disk emulator 330A, sothat the virtual disk 240 is mapped to the base disk file 140A, insteadof to the current COW disk file, which may be the original COW disk file140B, or it may be one of the subsequent COW disk files created duringthe step 874. The committing of the COW disk file 140B and the changingof the disk mapping to the base disk file 140A are highlighted in FIG.2F using thick lines. After the step 884, the method of FIG. 3F proceedsto a step 886. At the step 886, the execution of the VM 200 resumes.Next, the method of FIG. 3F ends at a step 888.

Returning to the description of FIG. 3A, after the step 834, the methodproceeds to a step 836. At the step 836, the process of generating thecheckpoint is completed, and the VM 200 continues normal operation,without any checkpointing activity. FIG. 2G illustrates the state of thevirtual computer system 700 at the step 836 of FIG. 3A. The virtualcomputer system 700 is generally in the same state as it was in the FIG.2A, before the initiation of the checkpoint, except that the system nowincludes a checkpointed state. The complete checkpointed state may bedetermined by reference to the checkpoint file 142. The checkpoint file142 contains the device state copy 142B and the VM memory copy 142C. Thecheckpoint file 142 also contains the disk file pointer 142A, whichpoints to the checkpoint disk file 140C. Thus, the checkpoint disk file140C also constitutes a part of the checkpointed state.

The above description of the method of FIG. 3A focused on the firstimplementation, in which the optional steps 830 and 834 are performed.As described above, if the optional steps 830 and 834 are not performed,the second implementation is realized. If the step 830 is not performed,then, after the step 828, the method of FIG. 3A proceeds to the step832. After the step 832, if the step 834 is not performed, then themethod proceeds to the step 836. FIG. 2H illustrates changes to thestate of the virtual computer system 700 during the steps 828 and 832 ofFIG. 3A, along with the state of the virtual computer system at the step836, if the optional steps 830 and 834 are not performed. At the step828, any remaining COW markings are removed from the VM memory 130A, asdescribed above, and as highlighted in bolded text in FIG. 2H. At thestep 832, the disk file pointer 142A is added to the checkpoint file 142as described above. However, in this case, the pointer points to thebase disk file 140A instead of the checkpoint disk file 140C. Theaddition of the disk file pointer 142A pointing to the base disk file140A is highlighted in FIG. 2H using thick lines and bolded text. FIG.2H also illustrates the state of the virtual computer system at the step836, after the checkpoint generation has completed. The completecheckpoint state includes the checkpoint file 142, including the devicestate copy 142B and the VM memory copy 142C, along with the base diskfile 140A. The virtual computer system continues operating with the VM200 using the COW disk file 140B. The COW disk file 140B may now beconsidered a perpetual COW disk.

Selecting between the first implementation and the second implementationinvolves a tradeoff. Using the perpetual COW disk in the secondimplementation avoids having to copy the base disk file 140A, which maytake a long period of time because the base disk file may be very large.On the other hand, operating the continuing VM with the perpetual COWdisk will cause some inefficiency in executing the continuing VM.

As described above, after the checkpoint has been completely generated,either as illustrated in FIG. 2G or in FIG. 2H, the same VM 200 or adifferent VM may be caused to begin executing from the checkpointedstate. A method according to the invention for starting a VM from acheckpointed state is illustrated in FIG. 3G. The method of FIG. 3G maybe also performed by the checkpoint software 342. The followingdescription assumes that the method of FIG. 3G is performed to cause theVM 200 to revert back to the checkpointed state. The followingdescription further assumes that the VM 200 is stopped prior to theperformance of the method.

The method of FIG. 3G begins at an initial step 900. At a step 902, thecheckpoint software 342 installs the device state copy 142B from thecheckpoint file 142. This step is basically the converse of the step 808of FIG. 3A, except that the device state is restored from the disk 140,instead of from the VMM memory 130B. All of the virtualized registers,data structures, etc. that were previously saved from the executionstate of the VM 200 are now restored to the same values they containedat the point that the checkpoint generation was initiated.

Next, at a step 904, the checkpoint software 342 restores the VM memorycopy 142C from the checkpoint file 142 into the VM memory 130A. Thisstep is basically the converse of the step 824 of FIG. 3A. Next, at astep 906, the checkpoint software makes a copy of the disk file to whichthe disk file pointer 142A of the checkpoint file 142 is pointing. Inthe case of FIG. 2G, a copy is made of the checkpoint disk file 140C,while, in the case of FIG. 2H, a copy is made of the base disk file140A. A copy of the respective file is made at the step 906 to enablethe same checkpoint to be used again at a later time. Alternatively, inthe case of FIG. 2H, a copy of the base disk file 140A may be made toenable the continuing VM 200 to continue executing using the COW diskfile 140B, which references the base disk file 140A. If there is nodesire to use the checkpoint again later and, for the case of FIG. 2H,if there is no desire to continue executing the VM 200, then the step906 may be skipped. Next, at a step 908, the configuration of the diskemulator 330A is modified so that the virtual disk 240 is mapped to thedisk file copy that was created during the step 906. As anotheralternative for enabling a checkpoint to be used multiple times or forenabling the continuing VM 200 to continue executing in the case of FIG.2H, a new COW disk file may be created referencing the disk file towhich the disk file pointer 142A is pointing, and the virtual disk 240may be mapped to the new COW disk file. This alternative using a new COWdisk file may be preferred in many situations because the checkpointdisk file may take a long time to copy.

Next, at a step 910, the execution of the VM 200 is resumed. At thispoint, the VM 200 will have substantially the same device state as ithad when the checkpoint generation was initiated, the VM memory 130Awill be in the same state, and the disk file used by the VM 200 willalso be in the same state. In the preferred embodiment, the VM 200 willbegin executing again in substantially the same manner as if the VM 200had been halted at the time the checkpoint generation was initiated, andis just now getting restarted.

Next, at a step 912, all pending input/output (IO) operations, includingpending disk operations and pending network operations, are marked ashaving completed. As described above, the results of all pending diskreads were incorporated into the VM memory 130A and the results of allpending disk writes were incorporated into the base disk file 140A,before the VM memory and the base disk file were used to generate thecheckpoint, so that the results of all pending disk reads will be seenby the VM 200 when it resumes execution from the checkpointed state.Also as described above, the pending network operations are ignored, andit is up to the respective network software packages to detect anynetwork packets that must be resent. Next, at a step 914, the VM 200 isinterrupted, as appropriate, for any pending IO operations, as if theyhave just completed. Thus, in particular, a pending disk operation ismarked as having completed in the step 912, and then the VM 200 isinterrupted to notify the VM that the disk operation has completed.Next, the method of FIG. 3G ends at a step 916. From this point, the VM200 will continue executing from the checkpointed state.

Returning to the techniques of this invention used for generatingcheckpoints, the method of FIG. 3A, with the optional steps 830 and 834,may be adapted in a variety of ways to generate additional checkpoints.FIGS. 4A through 4D illustrate how multiple checkpoints may be generatedwithout having to copy any disk files. Depending on the particularimplementation, disk files may be quite large and may requiresubstantial periods of time to copy. The virtual computer system 700 maynot have sufficient idle processing time to copy such a large disk file,without interfering with the operation of the VM 200, or other VMs orapplications within the virtual computer system.

FIG. 4A is a simplified version of FIG. 2H, representing the state ofthe virtual computer system 700 after the generation of a firstcheckpoint using the second implementation of the first embodiment. FIG.4A shows the VM 200, the base disk file 140A, the first COW disk file140B, and the first checkpoint file 142, including the first disk filepointer 142A. As represented in FIG. 4A, the VM 200 is using the firstCOW disk file 140B as a perpetual COW disk file. The COW disk file 140Breferences the base disk file 140A. The first disk file pointer 142Aindicates that the base disk file 140A constitutes a part of the firstcheckpoint file 142, along with the contents of the first checkpointfile 142.

Now suppose that a second checkpoint generation is initiated. Thecheckpoint software 342 will again perform the method of FIG. 3A, or aslightly modified form of the method of FIG. 3A, to generate a secondcheckpoint. FIG. 4B illustrates the state of the virtual computer system700 during the generation of the second checkpoint. At the step 802, thecheckpoint software generates a second COW disk file 140D, whichreferences the first COW disk file 140B. At the step 810, the diskemulator 330A is configured so that the virtual disk 240 is mapped tothe second COW disk file 140D, instead of to the first COW disk file140B. As shown in FIG. 4B, at this point, the VM 200 is using the secondCOW disk file 140D, which references the first COW disk file 140B, whichfurther references the base disk file 140A. The first disk file pointer142A still points to the base disk file 140A.

FIGS. 4C and 4D illustrate two options for completing the generation ofthe second checkpoint. In FIG. 4C, the second checkpoint effectivelyoverwrites the first checkpoint, so that the first checkpoint iseliminated. In FIG. 4D, the second checkpoint is saved independently ofthe first, so that the first checkpoint is retained. Referring first toFIG. 4C, at the step 820 of FIG. 3A, the device state 130C is saved to asecond checkpoint file 144, and, at the step 824, the VM memory 130A isalso saved to the second checkpoint file 144. Also, at the step 834, thefirst COW disk file 140B is committed to the base disk file 140A, andthe second COW disk file 140D is changed to reference the base disk file140A. At the step 832 of FIG. 3A, a second disk file pointer 144A isadded to the second checkpoint file 144, pointing to the base disk file140A. After the first COW disk file 140B is committed to the base diskfile 140A, the first checkpoint file 142 is deleted because it no longerrepresents a valid checkpoint. The base disk file 140A to which thefirst disk file pointer 142A points now includes changes that occurredafter the first checkpoint was taken, while the remainder of the firstcheckpoint file 142 does not include any changes subsequent to the firstcheckpoint. Thus, FIG. 4C shows a single checkpoint file, the secondcheckpoint file 144, which includes the device state copy and the VMmemory copy of the second checkpoint, along with the disk file pointer144A, pointing to the base disk file 140A, which now includes thechanges to the disk file through the second checkpoint, which had beencaptured in the first COW disk file 140B. The state of the virtualcomputer system 700 reflected in FIG. 4C is generally the same as thestate reflected in FIG. 4A, except that the second checkpoint is saved,instead of the first checkpoint. Subsequent checkpoints can be generatedin the same manner, with each subsequent checkpoint overwriting theprevious checkpoint.

The state of FIG. 4D can also result from the state of FIG. 4B, byapplying a slightly different variation of the general method of FIG.3A. At the step 820 of FIG. 3A, a second checkpoint file 144 isgenerated, and the device state 130C is saved to this second checkpointfile 144, instead of overwriting the device state copy 142B of the firstcheckpoint file 142. Also, at the step 824 of FIG. 3A, the VM memory130A is saved to the second checkpoint file 144, instead of overwritingthe VM memory copy 142C of the first checkpoint file 142. At the step832 of FIG. 3A, a second disk file pointer 144A is added to the secondcheckpoint file 144, pointing to the first COW disk file 140B. In thissituation, the optional step 834 of FIG. 3A is not performed, and boththe first COW disk file 140B and the second COW disk file 140D areretained. At the end of the generation of the second checkpoint, asillustrated in FIG. 4D, the VM 200 is using the second COW disk file140D. The second COW disk file 140D references the first COW disk file140B, and the first COW disk file 140B references the base disk file140A. Both the first and second checkpoints are valid, so that the VM200, or another VM, can be caused to begin executing from either ofthese checkpointed states. The first checkpointed state comprises thecontents of the first checkpoint file 142, and the base disk file 140A,as indicated by the first disk file pointer 142A. The secondcheckpointed state comprises the contents of the second checkpoint file144, and the first COW disk file 140B, as indicated by the second diskfile pointer 144A.

Subsequent checkpoints can also be generated in the same manner, with anadditional COW disk file being generated for use by the VM 200 eachtime, and with a new checkpoint file being created each time. Oneadvantageous use of this invention is to generate checkpoints at regulartime intervals, so that, if necessary or desirable, the VM may be rolledback to a relatively recent checkpointed state. Such an approach canlead to a lot of checkpoints in a relatively short period of time,though, if checkpoints are generated frequently. Any of these multiplecheckpoints can be eliminated at any time, if desired. For example, thefirst checkpoint of FIG. 4D can be eliminated by deleting the firstcheckpoint file 142, committing the first COW disk file 140B into thebase disk file 140A, changing the second COW disk file 140D to referencethe base disk file 140A, and changing the second disk file pointer 144Ato point to the base disk file 140A.

FIGS. 5A through 5E illustrate still other approaches for generatingmultiple checkpoints, and for eliminating checkpoints, as desired. Theapproaches depicted in FIGS. 5A through 5E may be considered a thirdimplementation of the first embodiment of the invention. The state ofFIG. 5A may be derived from the state of FIG. 4D. From the state of FIG.4D, the base disk file 140A is copied to a base disk file copy 141A, andthe first COW disk file 140B is copied to a first COW disk file copy141B, as shown in FIG. 5A. As the first COW disk file 140B is copiedover to the first COW disk file copy 141B, the copy is re-parented toreference the base disk file copy 141A, instead of the base disk file140A. Techniques for changing the parent of a COW disk file are known inthe art and depend on the particular COW implementation that is used.For example, in some implementations, a data structure related to theCOW disk file contains a pointer to the parent disk file. In such acase, the COW disk file may be re-parented by simply changing thepointer to point to the new parent, instead of the old parent. Also, thefirst disk file pointer 142A is changed to point to the base disk filecopy 141A, instead of the base disk file 140A, and the second disk filepointer 144A is changed to point to the first COW disk file copy 141B,instead of the first COW disk file 140B.

Next, the first COW disk file 140B is committed into the base disk file140A, and the second COW disk file 140D is changed to reference the basedisk file 140A. Now, the virtual computer system 700 is in the stateillustrated in FIG. 5B. The VM 200 is using the second COW disk file140D, which references the base disk file 140A, which includes thechanges that had been captured in the first COW disk file 140B. Thereare also two saved checkpoints. The first checkpoint comprises thecontents of the first checkpoint file 142 and the contents of the basedisk file copy 141A, as indicated by the first disk file pointer 142A.The second checkpoint comprises the contents of the second checkpointfile 144 and the contents of the first COW disk file copy 141B, asindicated by the second disk file pointer 144A.

Next, a third checkpoint is generated, as illustrated in FIG. 5C. Athird COW disk file 140E is created, which references the second COWdisk file 140D, and the disk emulator 330A is configured so that the VM200 uses the third COW disk file 140E, instead of the second COW diskfile 140D. Next, the device state 130C and the VM memory 130A are savedto a new, third checkpoint file 146. Also, the second COW disk file 140Dis copied into a new, second COW disk file copy 141D, and the second COWdisk file copy 141D is re-parented to the first COW disk file copy 141B,instead of the base disk file 140A. Next, a new, third disk file pointer146A is added to the third checkpoint file 146, pointing to the secondCOW disk file copy 141D.

Next, as shown in FIG. 5D, the second COW disk file 140D is committedinto the base disk file 140A, and the third COW disk file 140E ischanged to reference the base disk file 140A. Now, after the generationof the third checkpoint, the VM 200 uses the third COW disk file 140E,which references the base disk file 140A. Also, all three checkpointsare retained. The first checkpoint comprises the contents of the firstcheckpoint file 142, along with the contents of the base disk file copy141A, as indicated by the first disk file pointer 142A. The secondcheckpoint comprises the contents of the second checkpoint file 144,along with the contents of the first COW disk file copy 141B, asindicated by the second disk file pointer 144A. The third checkpointcomprises the contents of the third checkpoint file 146, along with thecontents of the second COW disk file copy 141D, as indicated by thethird disk file pointer 146A.

The third implementation of FIGS. 5A through 5E is similar to the secondimplementation of FIGS. 4A through 4D in that numerous checkpoints maybe created, and selected checkpoints may be eliminated, as desired. Forexample, as shown in FIG. 5E, the first COW disk file copy 141B may becommitted into the base disk file copy 141A, the second COW disk filecopy 141D may be changed to reference the base disk file copy 141A, thesecond disk file pointer 144A may be changed to point to the base diskfile copy 141A, and the first checkpoint file 142 may be deleted, toeliminate the first checkpoint. Various additional checkpoints may begenerated, while any subset of the checkpoints may be eliminated, usingthe techniques illustrated in FIGS. 5A through 5E. Again, there is atradeoff between the second implementation of FIGS. 4A through 4D andthe third implementation of FIGS. 5A through 5E. The secondimplementation generally does not require that disk files be copiedduring the generation of checkpoints, while the third implementationlimits the number of COW disk files through which the continuing VM mustexecute, which limits the performance degradation for the continuing VM.

The method of FIG. 3A can be used to generate one or more checkpointsfor a VM that is currently running. The method of FIG. 3G can be used tocause a VM to begin executing from one of the checkpoints generated bythe method of FIG. 3A. These methods may be modified in a variety ofways within the scope of this invention. In particular, pending IOoperations may be handled in different manners, depending on theparticular implementation. Also, a number of other steps may be taken tospeed up the performance of these methods. In particular, various stepsmay be taken to avoid having to save pages of the VM memory 130A to thecheckpoint file 142. For example, if one or more pages of memory havenot changed over multiple checkpoints, redundant copies of the page(s)need not be stored. Instead, later checkpoints may include a pointer toan earlier checkpoint, in place of a duplicate memory page.

This invention may also be combined in a synergistic manner with otherinventions that are owned by the assignee of this invention. One examplerelates to U.S. patent application Ser. No. 09/915,045 (“the '045application”), entitled Content-Based, Transparent Sharing of MemoryPages, which is incorporated here by reference. The '045 applicationdiscloses a method by which multiple memory pages within a VM thatcontain the exact same content may be consolidated into a single memorypage that is marked COW. For example, if multiple instances of the sameapplication are executing in the VM, one or more pages of theapplication may be duplicated in memory. Also, there are often multiplememory pages that contain nothing but zeroes. When multiple copies ofthe same page are detected, all but one such page may be freed for otheruses, and the remaining page may be marked COW and used by all theprocesses that need a copy of the page. If any such process attempts towrite to the COW page, then that process is given its own copy of thepage with read and write capabilities. Meanwhile, substantial memoryresources may be conserved by eliminating the duplicated use of theother copies of the same page. The invention of the '045 application maybe synergistically combined with the present invention in a couple ofways. First, the memory pages that are shared according to the inventionof the '045 application are already marked COW, which saves some timeduring the step 806 of FIG. 3A, in which the memory pages of the VMmemory 130A are marked COW. Second, the checkpoint software 342 canavoid writing duplicated memory pages to the checkpoint file 142 duringthe step 824, which conserves disk space on the disk 140 and reduces thetime required to perform the step 824.

Another invention with which this invention may be synergisticallycombined is disclosed in U.S. patent application Ser. No. 09/668,666(“the '666 application”), entitled System and Method for ControllingResource Revocation in a Multi-Guest Computer System, which is alsoincorporated here by reference. The '666 application discloses a methodby which memory pages are requested of the guest OS of a first VM sothat the memory pages may be used in a second VM. In this situation, thememory pages are not actually used within the first VM. Thus, the unusedmemory pages need not be stored to the checkpoint file 142 during thestep 824 of FIG. 3A.

This invention may also be extended to generate one checkpoint for eachof multiple VMs, with each of the checkpoints for the multiple VMs beinginitiated at substantially the same time. The multiple VMs may all beexecuting within the same physical computer system, or they may bedistributed over multiple physical computer systems. For example,suppose that three VMs are executing within a single physical computersystem to provide a single web service, such as a database server with asearch engine. A first VM may provide front-end functions such ashandling requests from clients, while a second VM and a third VMimplement back-end functions, such as each VM containing different partsof the database. The first VM may load-balance the requests from theclients between the second VM and the third VM. The checkpoint software342 of this invention may be used to initiate a checkpoint for each ofthese three VMs at substantially the same time. This task may beaccomplished in a variety of ways. For example, a single checkpointsoftware entity 342 may perform the checkpoint generation for all of thethree VMs; or a separate instance of the checkpoint software 342 may becontained in each of three VMMs, with each VMM supporting a differentone of the VMs, and a different instance of the checkpoint software 342performing the checkpoint generation for each of the respective VMs.

Also, various techniques may be used to ensure that the initiation ofthe multiple checkpoints is adequately synchronized. For example, ifmultiple VMs are executing within a single multiprocessor physicalcomputer system, with each of the multiple VMs executing on a separateprocessor, then separate instances of the checkpoint software 342 maycoordinate the initiation of the multiple checkpoints using standardinterprocessor communication techniques. Similarly, if multiple VMs areexecuting in a multitasking environment, separate instances of thecheckpoint software 342 may communicate with each other using knowninterprocess communication techniques. As another alternative, multipleinstances of the checkpoint software 342 may initiate the generation ofa checkpoint independently of each other, but based on a common timereference. For example, each of multiple VMs may be executing onseparate physical computer systems, with each of the physical computersystems connected to a computer network. Then, a separate instance ofthe checkpoint software 342 may initiate a checkpoint generation foreach of the VMs on each of the separate physical computer systems, at aspecified time, based on the known network time protocol (NTP), forexample. The NTP may be used in this manner to generate synchronizedcheckpoints for multiple VMs on a periodic basis, for example.

Once a set of synchronized checkpoints is generated for each of multiplerelated VMs, the entire set of VMs may subsequently be restarted,effectively from the same point in time. In this manner, an entiresystem of multiple VMs may be consistently checkpointed at substantiallythe same point in time.

What is claimed is:
 1. A method for generating a checkpoint for avirtual machine (VM) using a virtual disk and VM memory, the methodcomprising: initiating generating a checkpoint for the VM; and uponinitiating the generating of the checkpoint and prior to a completion ofgenerating the checkpoint for the VM: saving a device state of the VM;saving contents of the VM memory of the VM; and separate from thegenerating of the checkpoint, enabling the VM to continue reading from,writing to, and executing code from the VM memory.
 2. The method ofclaim 1, wherein the virtual disk is initially mapped to a parent diskfile on a physical disk, and wherein the step of maintaining, in anunmodified state, the contents of the virtual disk comprises: creating acopy-on-write (COW) disk file pointing to the parent disk file in use bythe VM; and mapping the virtual disk to the COW disk file.
 3. The methodof claim 2, wherein content for the COW disk file is contained with thebase disk file, and the COW disk file includes pointers to data in thebase disk file.
 4. The method of claim 2, further comprising switchingthe VM to read from and write to the COW disk file instead of the parentdisk file so that the VM reads from and writes to the COW disk file andso that the VM reads from, writes to, and executes code from the VMmemory.
 5. The method of claim 2, further comprising: reissuing apending disk read; and directing data read from the parent disk tomemory pages of the VM.
 6. The method of claim 2, further comprising:handling disk COW faults to the COW disk file; and handling memory COWfaults to the original VM memory to generate copies of the original VMmemory for read, write, and execution use by the VM.
 7. The method ofclaim 2, wherein the VM is still running when the COW disk file iscreated.
 8. The method of claim 1, further comprising: copying the basedisk file after any pending disk writes complete; and using the copy ofthe base disk file for the checkpoint.
 9. The method of claim 1, whereinsaving the device state of the VM comprises saving an instructionpointer and a plurality of registers and settings for one or morevirtual devices.
 10. A virtual computing system comprising: a virtualmachine (VM) memory; a VM that reads from, writes to, and executes codefrom the VM memory; a virtual disk; and a processor programmed to:initiate generating a checkpoint; and upon initiating the generating ofthe checkpoint and prior to a completion of generating the checkpoint:save a device state of the VM; save contents of the VM memory of the VM;and enable the VM to continue the reading from, the writing to, and theexecuting code from the VM memory.
 11. The system of claim 10, whereinthe virtual disk is initially mapped to a parent disk file on a physicaldisk, and wherein the step of maintaining, in an unmodified state, thecontents of the virtual disk comprises: creating a copy-on-write (COW)disk file pointing to the parent disk file in use by the VM; and mappingthe virtual disk to the COW disk file, wherein the VM is still runningwhen the COW disk file is created.
 12. The system of claim 11, whereincontent for the COW disk file is contained with the base disk file, andthe COW disk file includes pointers to data in the base disk file. 13.The system of claim 11, wherein the processor is further programmed toswitch the VM to read from and write to the COW disk file instead of theparent disk file so that the VM reads from and writes to the COW diskfile and so that the VM reads from, writes to, and executes code fromthe VM memory.
 14. The system of claim 11, wherein the processor isfurther programmed to: reissue a pending disk read; and direct data readfrom the parent disk to memory pages of the VM.
 15. The system of claim11, further comprising: handling disk COW faults to the COW disk file;and handling memory COW faults to the original VM memory to generatecopies of the original VM memory for read, write, and execution use bythe VM.
 16. A computer-readable storage medium comprisingcomputer-executable instructions that, when executed by a processor at atime of initiating generating a checkpoint for a virtual machine (VM)using a virtual disk and a VM and prior to a completion of generatingthe checkpoint, cause the processor to: save a device state of the VM;save contents of the VM memory of the VM; and separate from thegenerating of the checkpoint, enable the VM to continue reading from,writing to, and executing code from the VM memory.
 17. Thecomputer-readable storage medium of claim 16, wherein the virtual diskis initially mapped to a parent disk file on a physical disk, andwherein the step of maintaining, in an unmodified state, the contents ofthe virtual disk comprises: creating a copy-on-write (COW) disk filepointing to the parent disk file in use by the VM; and mapping thevirtual disk to the COW disk file, wherein the VM is still running whenthe COW disk file is created.
 18. The computer-readable storage mediumof claim 17, wherein content for the COW disk file is contained with thebase disk file, and the COW disk file includes pointers to data in thebase disk file.
 19. The computer-readable storage medium of claim 17,wherein the computer-executable instructions further cause the processorto switch the VM to read from and write to the COW disk file instead ofthe parent disk file so that the VM reads from and writes to the COWdisk file and so that the VM reads from, writes to, and executes codefrom the VM memory.
 20. The computer-readable storage medium of claim17, wherein the computer-executable instructions further cause thepossessor to: reissue a pending disk read; and direct data read from theparent disk to memory pages of the VM.